package me.apidemo.a04regexdemo1;

public class RegexDemo6 {
    public static void main(String[] args) {
        String regex1 = "(.).+\\1";
        System.out.println("a123a".matches(regex1));
        System.out.println("a123b".matches(regex1));
        System.out.println("----------------------");

        String regex2 = "(.+).+\\1";
        System.out.println("abc123abc".matches(regex2));
        System.out.println("ab123ac".matches(regex2));
        System.out.println("----------------------");

        //(.)把首字母看成一组
        // \\2把首字母拿出来再次使用
        // *作用于\\2，表示后面的内容出现一次或多次
        String regex3 = "((.)\\2*).+\\1";
        System.out.println("aaa123aaa".matches(regex3));
        System.out.println("aa13ab".matches(regex3));
    }
}
